import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wangziyi_app/constans/constans.dart';
import 'package:wangziyi_app/constans/toast.dart';
import 'package:wangziyi_app/main.dart';

class AppThemeColorItem extends StatelessWidget {
  int _cindex;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("选择主题颜色"),
          centerTitle: true,
        ),
        body: GridView.builder(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              mainAxisSpacing: 1,
              childAspectRatio: 1,
              crossAxisSpacing: 1,
              crossAxisCount:5),
          itemBuilder: (BuildContext context, int index) {
            return GestureDetector(
              child: Container(
                margin: EdgeInsets.all(10),
                decoration: BoxDecoration(
                    color: AppThemeColors().themeColorList[index],
                    borderRadius: BorderRadius.all(Radius.circular(50))),
                child: check(index),
              ),
              onTap: () {
                _cindex = index;
                if (_cindex == index) {}

                //将选择的颜色传给Model
                colorModel.increment(AppThemeColors().themeColorList[index],index);
                // colorModel.incrementIndex(index);
                //将选择的颜色存储下来，下次打开记录该颜色
                sharedPreferences.then((value) {
                  value.setInt("themeColor", index);
                });
              },
            );
          },
          itemCount: AppThemeColors().themeColorList.length,
        ));
  }

  Widget check(int index) {
    int cindex = colorModel.appThemeColorIndex;
    if (index == cindex) {
      return Icon(

        Icons.check,
        color: Colors.white,

      );
    } else {
      return Container();
    }
  }
}
